package com.baifc.web;

import com.baifc.datasource.SpittleRepository;
import com.baifc.entity.Spittle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * projectName: spring-in-action-web
 * packageName: com.baifc.web
 * Created: 2019/5/9.
 * Auther: baifc
 * Description:
 */
@Controller
public class SpittleController {

    private SpittleRepository spittleRepository;

    @Autowired
    public SpittleController(SpittleRepository spittleRepository) {
        this.spittleRepository = spittleRepository;
    }

    @RequestMapping(value = "/spittle", method = RequestMethod.GET)
    public String spittle(Model model) {
        List<Spittle> spittleList = spittleRepository.findSpittles(Long.MAX_VALUE, 20);
        for (Spittle spittle : spittleList) {
            System.out.println(spittle);
        }
//        model.addAttribute("spittleList", spittleList);
        model.addAttribute(spittleList);
        return "spittle";
    }



}
